/*客户表新增与修改,作者:高振中,日期:2021-03-24 13:28:03*/
<template>
  <el-dialog :title="title" width="800px" :visible.sync="show" :close-on-click-modal="false" :close-on-press-escape="false">
    <el-form :model="form" ref="form" :rules="rules" label-width="100px">
      <el-row>
        <el-col :span="12">
          <el-form-item label="用户名" prop="username"><el-input placeholder="请输入用户名" v-model="form.username" size="mini" /></el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="密码" prop="password"><el-input placeholder="请输入密码" v-model="form.password" size="mini" /></el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="微信号" prop="wechat"><el-input placeholder="请输入微信号" v-model="form.wechat" size="mini" /></el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="地址" prop="address"> <el-input placeholder="请输入地址" v-model="form.address" size="mini" /> </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="头像" prop="avatar"><el-input placeholder="请输入头像" v-model="form.avatar" size="mini" /></el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="备注" prop="remark"><el-input placeholder="请输入备注" v-model="form.remark" size="mini" /></el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="电话号" prop="tel"><el-input placeholder="请输入电话号" v-model="form.tel" size="mini" /></el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="会员等级" prop="levelId"><el-input placeholder="请输入会员等级" v-model="form.levelId" size="mini" /></el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="注册时间" prop="createTime"><el-input placeholder="请输入注册时间" v-model="form.createTime" size="mini" /></el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="修改时间" prop="updateTime"><el-input placeholder="请输入修改时间" v-model="form.updateTime" size="mini" /></el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div style="text-align: right"><el-button @click="show = false" size="mini">取消</el-button><el-button type="primary" @click="save()" size="mini">确定</el-button></div>
  </el-dialog>
</template>
<script>
export default {
  props: ["loadData"],
  components: {},
  data() {
    return {
      title: "",
      form: this.initForm(),
      dialogMode: "save",
      show: false,
      rules: {
        username: [{ required: true, message: "请输入用户名", trigger: "blur" }],
        password: [{ required: true, message: "请输入密码", trigger: "blur" }],
        wechat: [{ required: true, message: "请输入微信号", trigger: "blur" }],
        address: [{ required: true, message: "请输入地址", trigger: "blur" }],
        avatar: [{ required: true, message: "请输入头像", trigger: "blur" }],
        remark: [{ required: true, message: "请输入备注", trigger: "blur" }],
        tel: [{ required: true, message: "请输入电话号", trigger: "blur" }],
        levelId: [{ required: true, message: "请输入会员等级", trigger: "blur" }],
        createTime: [{ required: true, message: "请输入注册时间", trigger: "blur" }],
        updateTime: [{ required: true, message: "请输入修改时间", trigger: "blur" }],
      },
    };
  },
  methods: {
    /*客户表-保存*/
    save() {
      this.$refs["form"].validate((valid) => {
        if (!valid) return;
        this.rq.post("/customer/" + this.dialogMode, this.form).then((res) => {
          if (res.code == 200) {
            this.show = false;
            this.$message.success(this.title + "成功!");
            this.loadData();
          } else this.$message.error(res.msg);
        });
      });
    },
    /*客户表-初始数据*/
    initForm() {
      return {
        id: null, // 主键
        username: null, // 用户名
        password: null, // 密码
        wechat: null, // 微信号
        address: null, // 地址
        avatar: null, // 头像
        remark: null, // 备注
        tel: null, // 电话号
        levelId: null, // 会员等级
        createTime: null, // 注册时间
        updateTime: null, // 修改时间
      };
    },
    /*客户表-新增*/
    addDialog() {
      this.title = "新增客户表";
      this.dialogMode = "save";
      this.form = this.initForm();
      this.show = true;
    },
    /*客户表-修改*/
    editDialog(row) {
      this.title = "修改客户表";
      this.dialogMode = "update";
      this.form = { ...row };
      this.show = true;
    },
  },
};
</script>
<style scoped lang="scss">
.custom-tree-node {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  padding-right: 8px;
}
</style>
